package com.toune.blackmusic.util;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatDelegate;

import com.avos.avoscloud.AVOSCloud;
import com.toune.blackmusic.service.MusicPlayerService;
import com.vondear.rxtool.RxTool;
import com.yanzhenjie.nohttp.NoHttp;
import com.yanzhenjie.nohttp.rest.RequestQueue;

/**
 * Created by lijunyan on 2017/2/8.
 */

public class MyApplication extends Application {
    private static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        Intent startIntent = new Intent(MyApplication.this, MusicPlayerService.class);
        startService(startIntent);
        initNightMode();
        //RxTool工具类初始化
        RxTool.init(context);

        //自定义初始化
        NoHttp.initialize(this);
        mRequestQueue = NoHttp.newRequestQueue();
        // 初始化参数依次为 this, AppId, AppKey
        AVOSCloud.initialize(this, "Hd3hs4xHKo393nYWqWJK83Ib-gzGzoHsz", "62yxyPlRVwdioD6GC3Sq9a7W");
    }

    //请求队列
    private static RequestQueue mRequestQueue;

    public static RequestQueue getmRequestQueue() {
        return mRequestQueue;
    }

    protected void initNightMode() {
        boolean isNight = MyMusicUtil.getNightMode(context);
        if (isNight) {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        } else {
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
    }

    public static Context getContext() {
        return context;
    }
}
